<?php 
class faq_home 
{ 
	function home_faq_list() 
	{ 
		global $mysql_conn,$v_file;
		$faq_user = $_COOKIE['user_name'];
		$list_page = $_GET['list_page'];
		$list_num = $_GET['list_num'];
		$sousuokey = $_GET['sousuokey'];
		if (empty($list_page)) $list_page = 1;
		if (empty($list_num)) $list_num = 10;
		if ($list_page < 5) {$list_page0 = 1;} else {$list_page0 = $list_page-4;}
		if ($list_page < 5) {$list_page1 = 1;} else {$list_page1 = $list_page-3;}
		if ($list_page < 5) {$list_page2 = 2;} else {$list_page2 = $list_page-2;}
		if ($list_page < 5) {$list_page3 = 3;} else {$list_page3 = $list_page-1;}
		if ($list_page < 5) {$list_page4 = 4;} else {$list_page4 = $list_page;}
		if ($list_page < 5) {$list_page5 = 5;} else {$list_page5 = $list_page+1;}
		if ($list_page < 5) {$list_page6 = 6;} else {$list_page6 = $list_page+2;}
		if ($list_page < 5) {$list_page7 = 7;} else {$list_page7 = $list_page+3;}
		if ($list_page < 5) {$list_page8 = 8;} else {$list_page8 = $list_page+4;}
		$page_btn .= "<button type='button' class='btn btn-white' onClick='list_page_go(".$list_page0.")'><i class='fa fa-chevron-left'></i></button>";
		$page_btn .= "<button class='btn btn-white' id='list_page".$list_page1."' onClick='list_page_go(".$list_page1.")'>".$list_page1."</button>";
		$page_btn .= "<button class='btn btn-white' id='list_page".$list_page2."' onClick='list_page_go(".$list_page2.")'>".$list_page2."</button>";
		$page_btn .= "<button class='btn btn-white' id='list_page".$list_page3."' onClick='list_page_go(".$list_page3.")'>".$list_page3."</button>";
		$page_btn .= "<button class='btn btn-white' id='list_page".$list_page4."' onClick='list_page_go(".$list_page4.")'>".$list_page4."</button>";
		$page_btn .= "<button class='btn btn-white' id='list_page".$list_page5."' onClick='list_page_go(".$list_page5.")'>".$list_page5."</button>";
		$page_btn .= "<button class='btn btn-white' id='list_page".$list_page6."' onClick='list_page_go(".$list_page6.")'>".$list_page6."</button>";
		$page_btn .= "<button class='btn btn-white' id='list_page".$list_page7."' onClick='list_page_go(".$list_page7.")'>".$list_page7."</button>";
		$page_btn .= "<button type='button' class='btn btn-white' onClick='list_page_go(".$list_page8.")'><i class='fa fa-chevron-right'></i></button>";
		$list_limit = ($list_page-1)*$list_num.",".$list_num;
		if (empty($sousuokey)) {
			$sql = "SELECT * from `faq` WHERE `faq_user` = '".$faq_user."' limit ".$list_limit;
		} else {
			$sql = "SELECT * from `faq` WHERE `faq_user` = '".$faq_user."' and `faq_q` = '".$sousuokey."'";
		}
		$result = mysql_query($sql,$mysql_conn);
		while(@$row=mysql_fetch_array($result)) {
			$faq_id = $row['faq_id'];
			$faq_user = $row['faq_user'];
			$faq_q = $row['faq_q'];
			$faq_f = $row['faq_f'];
			$faqlist .= "<tr>";
			$faqlist .= "<td>".$faq_id."</td>";
			$faqlist .= "<td>".$faq_q."</td>";
			$faqlist .= "<td>".$faq_f."</td>";
			$faqlist .= "<td>";
			$faqlist .= "<a href='#' class='btn btn-white btn-xs' onClick='home_faq_del(".$faq_id.");'><i class='fa fa-trash-o'></i> 删除 </a>";
			$faqlist .= "</td></tr>";
		}
		require($v_file);
	}
	function home_faq_add() 
	{ 
		global $mysql_conn,$v_file;
		$faq_user = $_COOKIE['user_name'];
		require($v_file);
	}
	function home_faq_add_do() 
	{ 
		global $mysql_conn;
		$faq_user = $_POST['faq_user'];
		$faq_q = $_POST['faq_q'];
		$sql="INSERT INTO faq (faq_id, faq_user, faq_q) VALUES (NULL,'$faq_user','$faq_q')";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		echo "2";//帮助添加成功
	}
	function home_faq_del_do() 
	{ 
		global $mysql_conn;
		$faq_id = $_POST['faq_id'];
		$faq_user = $_COOKIE['user_name'];
		$sql = "DELETE from `faq` WHERE `faq_id` = '".$faq_id."' and `faq_user` = '".$faq_user."' ";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		echo "2";
	}
} 
/* End of file democontroller.php */ 